package com.example.c5c6;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class SerletContextTest1 extends HttpServlet {
    private ServletConfig config;
    public SerletContextTest1(){
        super();
    }
    @Override
    public void destroy(){
        super.destroy();
    }
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        this.config = config;
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        context=this.config.getServletContext();
        String url = request.getParameter("url");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD><TITLE>ServletContext</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("获取链接数据库的初始化参数:"+"<br/>");
        out.println("url:"+url+"<br/>");
        out.println("password:"+password+"<br/>");
        out.println("</BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
